public class MyArrayList {
    public String[] data = null;
    public int size = 0;

    public MyArrayList(){
        data = new String[10];
    }
    public MyArrayList(int capacity){
        if (capacity <= 10){
            capacity = 10;
        }
        data = new String[capacity];
    }

    public void resize(){
        //1.扩大容量
        String[] newData = new String[(int)(data.length * 1.5)];
        //2.搬运
        for (int i = 0; i < data.length; i++){
           newData[i] = data[i];
        }
        //新数组代替旧数组
        data = newData;
    }

    public void add(String elem){
        if (size >= data.length){
            resize();
        }
        data[size] = elem;
        size++;
    }
    public void add(int index, String elem){
        
    }
    public String toString(){
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("[");
        for (int i = 0; i < size; i++){
            stringBuilder.append(data[i]);
            if (i < size - 1){
                stringBuilder.append(", ");
            }
        }
        stringBuilder.append("]");
        return stringBuilder.toString();
    }
    public static void test1(){
        MyArrayList list = new MyArrayList();
        list.add("哥哥");
        list.add("弟弟");
        list.add("1");
        list.add("1");
        list.add("1");
        list.add("1");
        list.add("1");
        list.add("1");
        list.add("1");
        list.add("1");
        list.add("1");
        list.add("1");
        list.add("1");
        list.add("1");
        System.out.println(list);
    }
    public static void main(String[] args) {
        test1();
    }
}
